﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LightManager
{
    public sealed class MusicPlayer
    {
        private WMPLib.WindowsMediaPlayer Player { get; set; }
        private WMPLib.IWMPPlaylist Playlist { get; set; }

        public MusicPlayer()
        {
            this.Player = new WMPLib.WindowsMediaPlayer();
            this.Player.settings.setMode("shuffle", true);

            if (this.Player.playlistCollection.getByName("lightmanager").count != 0)
            {
                this.Playlist = this.Player.playlistCollection.getByName("lightmanager").Item(0);
                this.Player.playlistCollection.remove(this.Playlist);
            }

            this.Playlist = this.Player.playlistCollection.newPlaylist("lightmanager");
            this.Playlist.appendItem(this.Player.newMedia(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "media", "battle1.mp3")));
            this.Playlist.appendItem(this.Player.newMedia(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "media", "battle2.mp3")));
            this.Playlist.appendItem(this.Player.newMedia(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "media", "battle3.mp3")));
            this.Playlist.appendItem(this.Player.newMedia(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "media", "battle4.mp3")));
        }

        public void Battle()
        {
            if (this.Player.playState == WMPLib.WMPPlayState.wmppsPlaying)
                if (string.IsNullOrEmpty(this.Player.URL))
                    return;

            this.Player.settings.setMode("loop", true);
            this.Player.currentPlaylist = this.Playlist;
            this.Player.controls.play();
        }

        public void Victory()
        {
            this.Player.settings.setMode("loop", false);
            this.Player.URL = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "media", "fanfare.mp3");
            this.Player.controls.play();
        }

        public bool Mute
        {
            get { return this.Player.settings.mute; }
            set { this.Player.settings.mute = value; }
        }
    }
}
